package com.nce.entity;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 *关键字
 * 
 * @author GT
 */
@Entity
//表名与类名不相同时重新定义表名.
@Table(name = "msg")
//默认的缓存策略.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Msg extends IdEntity{
	
	private String qqid;
	private Date ctime;
	private String username;
	private String content;
	private String qqgroup;
	private Integer wordCounts;
	private Integer lineNumber;
	private String lightContent;
	
	private Vp vp;
	
	
	@Transient
	public Vp getVp() {
		return vp;
	}
	public void setVp(Vp vp) {
		this.vp = vp;
	}


	@Transient
	public Integer getLineNumber() {
		return lineNumber;
	}
	
	@Transient
	public String getLightContent() {
		if(StringUtils.isEmpty(lightContent)){
			return getContent();
		}
		return lightContent;
	}
	public void setLightContent(String lightContent) {
		this.lightContent = lightContent;
	}
	public void setLineNumber(Integer lineNumber) {
		this.lineNumber = lineNumber;
	}
	public String getQqid() {
		return qqid;
	}
	public void setQqid(String qqid) {
		this.qqid = qqid;
	}
	public Date getCtime() {
		return ctime;
	}
	public void setCtime(Date ctime) {
		this.ctime = ctime;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	
	
	
	
	public Integer getWordCounts() {
		return wordCounts;
	}
	public void setWordCounts(Integer wordCounts) {
		this.wordCounts = wordCounts;
	}
	public String getQqgroup() {
		return qqgroup;
	}
	public void setQqgroup(String qqgroup) {
		this.qqgroup = qqgroup;
	}
	@Override
	public String toString() {
		return "Msg [content=" + content + ", ctime=" + ctime + ", lineNumber="
				+ lineNumber + ", qqgroup=" + qqgroup + ", qqid=" + qqid
				+ ", username=" + username + ", wordCounts=" + wordCounts
				+ ", id=" + id + "]";
	}

	public String formatToTxt(int i) {
		StringBuffer sb = new StringBuffer();
		Format formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
	    String dateStr = formatter.format(ctime);
		sb.append(ctime).append("  ").append(username).append("(").append(qqid).append(")  ").append("\r\n");
		sb.append(content);
		return sb.toString();
	}
	public String formatToTxtWithVp(int i) {
		StringBuffer sb = new StringBuffer();
		Format formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
	    String dateStr = formatter.format(ctime);
		sb.append(ctime).append("  ").append(username).append("(").append(qqid).append(")  ").append("\r\n");
		sb.append(vp.getUsername()).append("  ").append(vp.getAddress()).append("\r\n");
		sb.append(content);
		return sb.toString();
	}
	
	
	
	

}
